package com.geekca.d8;

public class TestStringMethod {
    public static void main(String[] args) {
        String str = "abce,}中";
        System.out.println("长度:" + str.length());

        System.out.println(str.charAt((2)));
        System.out.println("最后一个字符:" + str.charAt(str.length() - 1));

        //转成字符数组
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.print(chars[i] + " ");

        }
        System.out.println();

        System.out.println(str.substring(3, 6));

        String replaced = str.replace("}", "#");
        System.out.println(replaced);

        // 分割字符串
        String myStr = "Tom,Jerry,刘备, 吴用";
        System.out.println("================");
        String[] splited = myStr.split(",");
        for (int i = 0; i < splited.length; i++) {
            System.out.println(splited[i]);
        }
    }
}
